package services

import (
	"bbs-go/internal/models/constants"

	"github.com/mlogclub/simple/sqls"
	"github.com/mlogclub/simple/web/params"

	"bbs-go/internal/models"
	"bbs-go/internal/repositories"
)

var ChatGroupsRequestService = newChatGroupsRequestService()

func newChatGroupsRequestService() *chatGroupsRequestService {
	return &chatGroupsRequestService{}
}

type chatGroupsRequestService struct {
}

func (s *chatGroupsRequestService) Get(id int64) *models.ChatGroupsRequest {
	return repositories.ChatGroupsRequestRepository.Get(sqls.DB(), id)
}

func (s *chatGroupsRequestService) Take(where ...interface{}) *models.ChatGroupsRequest {
	return repositories.ChatGroupsRequestRepository.Take(sqls.DB(), where...)
}

func (s *chatGroupsRequestService) Find(cnd *sqls.Cnd) []models.ChatGroupsRequest {
	return repositories.ChatGroupsRequestRepository.Find(sqls.DB(), cnd)
}

func (s *chatGroupsRequestService) FindPageByParams(params *params.QueryParams) (list []models.ChatGroupsRequest, paging *sqls.Paging) {
	return repositories.ChatGroupsRequestRepository.FindPageByParams(sqls.DB(), params)
}

func (s *chatGroupsRequestService) FindPageByCnd(cnd *sqls.Cnd) (list []models.ChatGroupsRequest, paging *sqls.Paging) {
	return repositories.ChatGroupsRequestRepository.FindPageByCnd(sqls.DB(), cnd)
}

func (s *chatGroupsRequestService) Create(t *models.ChatGroupsRequest) error {
	return repositories.ChatGroupsRequestRepository.Create(sqls.DB(), t)
}

func (s *chatGroupsRequestService) Update(t *models.ChatGroupsRequest) error {
	return repositories.ChatGroupsRequestRepository.Update(sqls.DB(), t)
}

func (s *chatGroupsRequestService) Updates(id int64, columns map[string]interface{}) error {
	return repositories.ChatGroupsRequestRepository.Updates(sqls.DB(), id, columns)
}

func (s *chatGroupsRequestService) UpdateColumn(id int64, name string, value interface{}) error {
	return repositories.ChatGroupsRequestRepository.UpdateColumn(sqls.DB(), id, name, value)
}

func (s *chatGroupsRequestService) DeleteByArticleId(articleId int64) {
	sqls.DB().Model(models.ChatGroupsRequest{}).Where("article_id = ?", articleId).UpdateColumn("status", constants.StatusDeleted)
}
